package util

import (
	"hundsun.com/hsl/hschain/common/crypto"
	"hundsun.com/hsl/hschain/protos"
)

//TxHashesToBytes hash转bytes
func TxHashesToBytes(txHashes []protos.Hash) []byte {
	hashSize, _ := crypto.HashSize()
	result := make([]byte, hashSize*len(txHashes))
	for i, txHash := range txHashes {
		for j, b := range txHash {
			result[i*hashSize+j] = b
		}
	}
	return result
}

//BytesToTxHashes bytes转hash
func BytesToTxHashes(bytes []byte) []protos.Hash {
	hashSize, _ := crypto.HashSize()
	txHashCount := len(bytes) / hashSize
	result := make([]protos.Hash, txHashCount)
	for i := 0; i < txHashCount; i++ {
		result[i] = bytes[hashSize*i : hashSize*(i+1)]
	}
	return result
}
